﻿package mortal.game.view.copy.expCopy
{
    import Message.DB.Tables.*;
    import Message.Public.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.component.window.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.manager.msgTip.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.scene3D.player.info.*;
    import mortal.game.utils.*;
    import mortal.game.view.copy.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class ExpCopyController extends CopyControllerBase
    {
        private var _expCopyModule:ExpCopyModule;

        public function ExpCopyController()
        {
            return;
        }// end function

        override protected function initView() : IView
        {
            if (this._expCopyModule == null)
            {
                this._expCopyModule = new ExpCopyModule();
                this._expCopyModule.addEventListener(WindowEvent.SHOW, this.onWinShow);
                this._expCopyModule.addEventListener(WindowEvent.CLOSE, this.onWinClose);
            }
            return this._expCopyModule;
        }// end function

        override protected function initServer() : void
        {
            Cache.instance.role.roleEntityInfo.addEventListener(EntityInfoEventName.UpdateLevel, this.showIcon);
            Dispatcher.addEventListener(EventName.ExpCopyModuleOpen, this.expCopyModuleOpen);
            NetDispatcher.addCmdListener(ServerCommand.ExpCopyPassInfo, this.expCopyPassInfo);
            NetDispatcher.addCmdListener(ServerCommand.ExpCopyHurtInfoUpdate, this.expCopyHurtInfoUpdate);
            NetDispatcher.addCmdListener(ServerCommand.ExpCopyInfoGet, this.showIcon);
            return;
        }// end function

        private function onWinShow(event:Event) : void
        {
            Dispatcher.addEventListener(EventName.ExpCopyEnter, this.expCopyEnter);
            return;
        }// end function

        private function onWinClose(event:Event) : void
        {
            Dispatcher.removeEventListener(EventName.ExpCopyEnter, this.expCopyEnter);
            return;
        }// end function

        private function showIcon(param1:Object) : void
        {
            if (Cache.instance.copy.expCopy.myExpCopyInfo && Cache.instance.role.entityInfo.level >= GameDefConfig.instance.getSystemOpenLevel(101))
            {
                ExpCopyIcon.instance.show();
            }
            else if (ExpCopyIcon.isViewShow)
            {
                ExpCopyIcon.instance.hide();
            }
            return;
        }// end function

        private function expCopyPassInfo(param1:int) : void
        {
            ExpCopyPassWin.instance.show();
            ExpCopyPassWin.instance.data = param1;
            return;
        }// end function

        override public function enterCopy(param1:TCopy) : void
        {
            super.enterCopy(param1);
            if (this.isViewShow)
            {
                view.hide();
            }
            return;
        }// end function

        private function expCopyHurtInfoUpdate(param1:SExpCopyHurtInfo) : void
        {
            if (!ExpCopyRightInfoWin.isViewShow)
            {
                ExpCopyRightInfoWin.instance.show();
            }
            ExpCopyRightInfoWin.instance.updateInfo(param1);
            return;
        }// end function

        private function expCopyModuleOpen(event:DataEvent) : void
        {
            if (this.isViewShow)
            {
                this.view.hide();
            }
            else if (Cache.instance.copy.expCopy.myExpCopyInfo)
            {
                this.view.show();
            }
            else
            {
                MsgManager.showRollTipsMsg(Language.getString(35217), MsgRollTipsType.msgRollTips3);
            }
            return;
        }// end function

        private function expCopyEnter(event:DataEvent) : void
        {
            CopyUtil.copyCheck(this.doEnterCopy);
            return;
        }// end function

        private function doEnterCopy() : void
        {
            GameProxy.copy.enterExpCopy();
            return;
        }// end function

        override public function leaveCopy() : void
        {
            super.leaveCopy();
            if (ExpCopyRightInfoWin.isViewShow)
            {
                ExpCopyRightInfoWin.instance.hide();
            }
            return;
        }// end function

    }
}
